#!/bin/sh

onlyGitShow=0
gitShowDays=14

if [ $# -gt 0 ]
then
	echo $1
	if [ $1 -gt 0 ]
	then
		onlyGitShow=1
		gitShowDays=$1
	fi
	echo onlyGitShow=$onlyGitShow gitShowDays=$gitShowDays
	#exit
fi

if [ $onlyGitShow -eq 0 ]
then
	#oc code
	find chatApp|grep -E '\.h$|\.m$|\.mm$'|xargs wc -l|sort -n

	#test code
	find chatAppTestCase|grep -E '\.h$|\.m$|\.mm$'|xargs wc -l|sort -n

	#php code
	ls ../docs/*.php|xargs wc -l|sort -n
fi

#git log by day
#date +%Y-%m-%d
nowTS=`date +%s`
#echo $nowTS
#nowTS=$((nowTS-86400))
#echo $nowTS
#date -j -f"%s" $nowTS "+%Y-%m-%d %H:%M:%S"
for loop in `seq 0 $gitShowDays`
do
	#echo $nowTS
	#yestoday=$((nowTS-86400))
	#tomorrow=$((nowTS+86400))
	#date -j -f"%s" $yestoday "+%Y-%m-%d 周%a"
	#date -j -f"%s" $tomorrow "+%Y-%m-%d 周%a"

	#ystDateStr=$(date -j -f"%s" $yestoday "+%Y-%m-%d")
	tdDateStr=$(date -j -f"%s" $nowTS "+%Y-%m-%d")
	#tmrDateStr=$(date -j -f"%s" $tomorrow "+%Y-%m-%d")
	#echo "yDateStr $yDateStr, tDateStr $tDateStr"
	echo ""
	date -j -f"%s" $nowTS "+%Y-%m-%d 周%a"
	# 精确到秒统计git log
	git --no-pager log --after="$tdDateStr 00:00:00" --before="$tdDateStr 23:59:59" --pretty=tformat: --numstat > codeChangeByGitlog.txt
	cat codeChangeByGitlog.txt |awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "增+改: %s, 删+改: %s, 净增: %s\n", add, subs, loc}'


	nowTS=$((nowTS-86400))
done

rm codeChangeByGitlog.txt
